package com.leo.quartz.common.request;

import com.leo.base.AbstractPageRequest;
import com.leo.quartz.common.lang.RunStatusEnum;
import com.leo.quartz.entity.TriggerPO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.PageRequest;

import java.util.HashMap;
import java.util.Map;

/**
 * @author liusl
 * @version 1.0
 * @date 2018/12/9 16:09
 */
public class MyJobDetailRequestParam extends AbstractPageRequest implements BaseRequestParam{

    private long jobId;
//    private String jobName;
    private String runStatus;
    private String ruleType;

    public long getJobId() {
        return jobId;
    }

    public void setJobId(long jobId) {
        this.jobId = jobId;
    }



    public String getRunStatus() {
        return runStatus;
    }

    public void setRunStatus(String runStatus) {
        this.runStatus = runStatus;
    }

    public String getRuleType() {
        return ruleType;
    }

    public void setRuleType(String ruleType) {
        this.ruleType = ruleType;
    }

    @Override
    public Map<String, Object> buildRule() {
        Map<String, Object> queryParams = new HashMap<>(10);
        if (this.jobId != 0) {
            queryParams.put("jobId", this.jobId);
        }
        if (StringUtils.isNotEmpty(this.ruleType)) {
            queryParams.put("triggerType", TriggerPO.TriggerType.valueOf(this.ruleType));
        }
        if(StringUtils.isNotEmpty(this.runStatus)){
            queryParams.put("triggerStatus", RunStatusEnum.valueOf(this.runStatus));
        }
        return queryParams;
    }

    @Override
    public PageRequest buildPageRequestBySort() {
        return PageRequest.of(page, limit);
    }

}
